import 'package:flutter/material.dart';
import 'package:wy/utils/screen_util.dart';

class HSquareList extends StatelessWidget {
  final List<Map> items;

  const HSquareList({Key key, this.items}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final screen = Screen(context);
    final rows = [];
    for (var i = 0; i < items.length; i += 3) {
      rows.add(items.sublist(i, i + 3));
    }

    return Container(
        margin: EdgeInsets.only(top: screen.calc(2)),
        padding: EdgeInsets.only(left: screen.calc(32), right: screen.calc(32)),
        child: Column(
          children: rows
              .map<Widget>((row) => Container(
                  margin: EdgeInsets.only(top: screen.calc(36)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: row
                        .map<Widget>((item) => Container(
                              width: screen.calc(214),
                              height: screen.calc(300),
                              child: Column(children: [
                                Image.asset(
                                  item['img'],
                                  width: screen.calc(214),
                                  height: screen.calc(214),
                                  fit: BoxFit.fill,
                                ),
                                Container(
                                  margin: EdgeInsets.only(top: screen.calc(8)),
                                  child: Text(item['title'],
                                      maxLines: 2,
                                      style: TextStyle(
                                        fontSize: screen.calc(24),
                                      )),
                                ),
                              ]),
                            ))
                        .toList(),
                  )))
              .toList(),
        ));
  }
}
